package com.nkym.controller;/*
 * @ClassName Yan
 * @Desc TODO
 * @Author 19637
 * @Date 2023/5/18 23:13
 * @Version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nkym.common.BaseResponse;

import com.nkym.entity.Yan;
import com.nkym.service.YanService;
import com.nkym.utils.ResultUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/yan")
public class YanController {
    @Resource
    YanService yanService;

    @PostMapping("")
    public BaseResponse<String> randomGetYan() {
        long a = yanService.count();
        int id = (int) (Math.random() * a);
        QueryWrapper<Yan> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        Yan yan = yanService.getOne(wrapper);
        return ResultUtil.dataOk(yan.getContent());
    }
}
